// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	10/19/2014 2:01:58 PM				
// -----------------------------

#include "InputManager.h"

#include "Application.h"
#include "Window.h"

#define KC(x)	((x & 0x80) > 0)

InputManager::InputManager()
{
	memset(m_Keys, 0, c_KeyCount);
	memset(m_PrevKeys, 0, c_KeyCount);
}

InputManager::~InputManager()
{
}

void InputManager::Update(Application* lpApp)
{
	memcpy_s(m_PrevKeys, c_KeyCount, m_Keys, c_KeyCount);
	GetKeyboardState(m_Keys);

	m_LastMousePosition = m_MousePosition;
	POINT mousePos = {};
	GetCursorPos(&mousePos);
	ScreenToClient(lpApp->GetWindow()->GetHandle(), &mousePos);
	m_MousePosition = Vector2((Float)mousePos.x, (Float)mousePos.y);
}

Bool InputManager::IsKeyDown(Int32 vKey) const
{
	return (KC(m_Keys[vKey]));
}
Bool InputManager::IsKeyPressed(Int32 vKey) const
{
	return (KC(m_Keys[vKey])) && !(KC(m_PrevKeys[vKey]));
}
Bool InputManager::IsKeyReleased(Int32 vKey) const
{
	return !(KC(m_Keys[vKey])) && (KC(m_PrevKeys[vKey]));
}

Vector2 InputManager::GetMousePosition() const
{
	return m_MousePosition;
}
Vector2 InputManager::GetPreviousMousePosition() const
{
	return m_LastMousePosition;
}